﻿/************************************************************************

   Extended Silverlight Toolkit

   Copyright (C) 2010-2012 Xceed Software Inc.

   This program is provided to you under the terms of the Microsoft Public
   License (Ms-PL) as published at http://extendedsilverlight.codeplex.com/license

   Please purchase a commercial version of this toolkit if you are using
   it in a commercial product. The commercial versions support the project,
   and also include more features for each control, priority support,
   source code, updates, removed watermark, and a proprietary license.

   Visit http://xceed.com and follow @datagrid on Twitter.

  **********************************************************************/

using System.Collections;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows;

namespace Xceed.Silverlight.Controls
{
  public abstract class DataNavigationConfiguration : DependencyObject, ISupportInitialize
  {
    #region ItemTemplate Property

    public static readonly DependencyProperty ItemTemplateProperty = DependencyProperty.Register(
      "ItemTemplate",
      typeof( DataTemplate ),
      typeof( DataNavigationConfiguration ),
      new PropertyMetadata( null ) );

    public DataTemplate ItemTemplate
    {
      get
      {
        return ( DataTemplate )this.GetValue( DataNavigationConfiguration.ItemTemplateProperty );
      }
      set
      {
        this.SetValue( DataNavigationConfiguration.ItemTemplateProperty, value );
      }
    }

    #endregion

    #region ItemContainerStyle Property

    public static readonly DependencyProperty ItemContainerStyleProperty = DependencyProperty.Register(
      "ItemContainerStyle",
      typeof( Style ),
      typeof( DataNavigationConfiguration ),
      new PropertyMetadata( null ) );

    public Style ItemContainerStyle
    {
      get
      {
        return ( Style )this.GetValue( DataNavigationConfiguration.ItemContainerStyleProperty );
      }
      set
      {
        this.SetValue( DataNavigationConfiguration.ItemContainerStyleProperty, value );
      }
    }

    #endregion

    public abstract IList GetKeys();

    #region ISupportInitialize Members

    void ISupportInitialize.BeginInit()
    {
      m_iSupportInitializeCount++;

      if( m_iSupportInitializeCount == 1 )
      {
        this.BeginInitCore();
      }
    }

    void ISupportInitialize.EndInit()
    {
      if( m_iSupportInitializeCount == 0 )
        return;

      m_iSupportInitializeCount--;

      if( m_iSupportInitializeCount == 0 )
      {
        this.IsInitialized = true;
        this.EndInitCore();
      }
    }

    protected bool IsInitialized
    {
      get;
      private set;
    }

    protected virtual void BeginInitCore()
    {
    }

    protected virtual void EndInitCore()
    {
    }

    private int m_iSupportInitializeCount;

    #endregion
  }
}
